from collections import defaultdict

from common.mssql_helper import g_msql_inst
from common.utils import create_uuid

__author__ = "Ypf"
_date_ = "2019/8/30-14:52"


class XsbFy(object):
    @staticmethod
    def get_xsjd_dic(sql,name):
        end_sql=sql%name
        res_list1 = g_msql_inst.fetch_all(end_sql)
        dic = defaultdict(dict)
        for (Q1,Q2,Q3,Q4) in res_list1:
            dic[name] = [Q1,Q2,Q3,Q4]
        return  dic

    @staticmethod
    def insert_xsch(db_insert_sql, dic, nowtime):
        for key in dic:
            id = create_uuid()
            dic[key].append(nowtime + '-01')
            dic[key].append(id)
            dic[key].append(key)
            value_tuple = tuple(dic[key])
            print(value_tuple)
            excuete_sql = db_insert_sql % value_tuple
            print(excuete_sql)
            g_msql_inst.db_excuete(excuete_sql)